﻿using System;
using System.Diagnostics;
using System.Windows.Input;
using Bookvar.ObjectModel;
using Bookvar.UI.Commands;

namespace Bookvar.UI.ViewModel
{
    public partial class TopicViewModel
    {
        private class NavigateToHyperlinkCommand : CommandModel
        {
            private readonly TopicViewModel viewModel;

            public NavigateToHyperlinkCommand(TopicViewModel viewModel)
                : base( BookvarCommands.NavigateToHyperlink )
            {
                this.viewModel = viewModel;
            }

            protected internal override void OnExecute( object sender, ExecutedRoutedEventArgs e )
            {
                Topic topic;
                if ( e.Parameter != null )
                {
                    topic = (Topic) e.Parameter;
                }
                else
                {
                    topic = viewModel.Topic;
                }

                Process.Start( topic.Hyperlink.ToString() );
            }

            protected internal override void OnCanExecute( object sender, CanExecuteRoutedEventArgs e )
            {
                e.CanExecute = viewModel.Topic.Hyperlink != default( Uri );
                e.Handled = true;
            }
        }
    }
}